import React, { Component } from 'react'
import { Suspense } from 'react'
import { Route, Switch, Redirect } from 'react-router-dom'
import { RouterItem } from "../type/router.d"
interface IPORT {
    routes: RouterItem[]
}
export default class routerView extends Component<IPORT>{
    render() {
        const { routes } = this.props
        return (
            <div>
                <Suspense fallback={<div>加载中</div>}>
                    <Switch>
                        {
                            routes && routes.map((item, index) => {
                                return <Route key={index} path={item.path} render={props => {
                                    return item.to?<Redirect to={item.to}></Redirect>:<item.component {...props} children={item.children}></item.component>
                                }}></Route>
                            })
                        }
                    </Switch>
                </Suspense>
            </div>

        )
    }
}
